package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepModuleNet;
import com.ruoyi.deeplearn.service.IDeepModuleNetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型网络Controller
 *
 * @author rww
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/deeplearn/moduleNet")
public class DeepModuleNetController extends BaseController
{
    @Autowired
    private IDeepModuleNetService deepModuleNetService;

    /**
     * 查询模型网络列表
     */
//    @PreAuthorize("@ss.hasPermi('module:moduleNet:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepModuleNet deepModuleNet)
    {
        startPage();
        List<DeepModuleNet> list = deepModuleNetService.selectDeepModuleNetList(deepModuleNet);
        return getDataTable(list);
    }
    @GetMapping("/list/all")
    public AjaxResult listAll(DeepModuleNet deepModuleNet)
    {
        List<DeepModuleNet> list = deepModuleNetService.selectDeepModuleNetList(deepModuleNet);
        return AjaxResult.success(list);
    }
    /**
     * 导出模型网络列表
     */
//    @PreAuthorize("@ss.hasPermi('module:moduleNet:export')")
    @Log(title = "模型网络", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepModuleNet deepModuleNet)
    {
        List<DeepModuleNet> list = deepModuleNetService.selectDeepModuleNetList(deepModuleNet);
        ExcelUtil<DeepModuleNet> util = new ExcelUtil<DeepModuleNet>(DeepModuleNet.class);
        util.exportExcel(response, list, "模型网络数据");
    }

    /**
     * 获取模型网络详细信息
     */
//    @PreAuthorize("@ss.hasPermi('module:moduleNet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deepModuleNetService.selectDeepModuleNetById(id));
    }

    /**
     * 新增模型网络
     */
//    @PreAuthorize("@ss.hasPermi('module:moduleNet:add')")
    @Log(title = "模型网络", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepModuleNet deepModuleNet)
    {
        return toAjax(deepModuleNetService.insertDeepModuleNet(deepModuleNet));
    }
    @PostMapping("config")
    public AjaxResult config(@RequestBody DeepModuleNet deepModuleNet)
    {
        if(deepModuleNet.getId()==null||deepModuleNet.getId()==0L){
            return AjaxResult.error("模型网络id不能为空");
        }
        return toAjax(deepModuleNetService.configDeepModuleNet(deepModuleNet));
    }


    /**
     * 修改模型网络
     */
//    @PreAuthorize("@ss.hasPermi('module:moduleNet:edit')")
    @Log(title = "模型网络", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepModuleNet deepModuleNet)
    {
        return toAjax(deepModuleNetService.updateDeepModuleNet(deepModuleNet));
    }

    /**
     * 删除模型网络
     */
//    @PreAuthorize("@ss.hasPermi('module:moduleNet:remove')")
    @Log(title = "模型网络", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepModuleNetService.deleteDeepModuleNetByIds(ids));
    }
}
